/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package parismetro;

import javafx.scene.CustomNode;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.Group;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import javafx.scene.Node;
import javafx.scene.text.TextAlignment;
import javafx.scene.layout.VBox;
import javafx.geometry.HPos;
import javafx.scene.layout.LayoutInfo;
import javafx.scene.layout.Stack;
import modele.RERTicket;
import javafx.scene.input.MouseEvent;

// IL FAUT INITIALISER text, htr ET montant
// htr =
/**
 * @author Hadrien
 */
def f: Font = Font { size: 18, name: "MyriadPro" };
def f2: Font = Font { size: 22, name: "MyriadPro" };

public class CadreDestFreq extends CustomNode {

    public-init var dest1: String;
    public-init var dest2: String;
    public-init var accueil: Accueil;
    public var s: Stack = Stack {
                content: [
                    Rectangle {
                        width: 345, height: 150
                        fill: Color.rgb(0, 113, 188)
                        arcHeight: 30
                        arcWidth: 30
                    },
                    VBox {
                        hpos: HPos.CENTER
                        layoutInfo: LayoutInfo { hpos: HPos.CENTER }
                        spacing: 5
                        content: [
                            Text {
                                layoutInfo: LayoutInfo { hpos: HPos.CENTER }
                                font: f2
                                content: "Destinations fréquentes"
                                fill: Color.WHITE
                            }
                            Stack {
                                layoutInfo: LayoutInfo { hpos: HPos.CENTER }
                                content: [
                                    Rectangle {
                                        arcWidth: 20, arcHeight: 20
                                        fill: Color.WHITE
                                        height: 50;
                                        width: 335;
                                    }
                                    Text {
                                        layoutInfo: LayoutInfo { hpos: HPos.CENTER }
                                        x: 5, y: 30,
                                        font: f
                                        content: bind dest1
                                        textAlignment: TextAlignment.CENTER
                                    }
                                ]
                                onMouseClicked: function(e: MouseEvent): Void {
                                    useFreqDest(dest1)
                                };
                            }, Stack {
                                layoutInfo: LayoutInfo { hpos: HPos.CENTER }
                                content: [
                                    Rectangle {
                                        arcWidth: 20, arcHeight: 20
                                        fill: Color.WHITE
                                        height: 50;
                                        width: 335;
                                    }
                                    Text {
                                        layoutInfo: LayoutInfo { hpos: HPos.CENTER }
                                        x: 5, y: 30,
                                        font: f
                                        content: bind dest2
                                        textAlignment: TextAlignment.CENTER
                                    }
                                ]
                                onMouseClicked: function(e: MouseEvent): Void {
                                    useFreqDest(dest2)
                                };
                            }
                        ]
                    }
                ]
            }

    override public function create(): Node {
        return s;
    }

    function useFreqDest(dest: String) {
        var t: RERTicket = RERTicket { orderList: accueil.main.orderList,
                    startStation: accueil.main.stationMachine,
                    endStation: dest
                };
        accueil.main.orderList.addOrder(t);
        accueil.main.optionEcran.previousStep = "accueil";
        accueil.main.changeContent("tplus");
    }

}
